<?php


namespace App\Common;


use App\Exceptions\BasicException;
use Illuminate\Support\Arr;

class ProductData
{
    static function getProductData($type,$productId)
    {
        $dataArr = [];
        switch ($type){
            case 2:
                $dataArr= self::headRes($productId);
                break;
            case 3:
                $dataArr= self::horse($productId);
                break;
            case 4:
                $dataArr= self::special($productId);
                break;
            case 6:
                $dataArr= self::gift($productId);
                break;
            case 8:// 道具
                $dataArr= self::item($productId);
                break;
            case 13:
            case 14:
            case 15:
            case 16:
            case 17:
            case 18:
                $dataArr = self::mallProduct($type, $productId);
                break;
        }
        return $dataArr;
    }

    public static function mallProduct($type, $productId)
    {
        $cateIdList = [
            13 => 27,
            14 => 33,
            15 => 25,
            16 => 26,
            17 => 23,
            18 => 24
        ];
        $specialRes = app("model_mall_products")->where([
            ["id", '=', $productId],
            ["category_id", '=', $cateIdList[$type]],
        ])->select('id as item_id','title as item_name') ->first();
        if (empty($specialRes)) {
            return [] ;
        }
        $specialRes['item_type'] = $type;
        return $specialRes  ;
    }

    static function item($specialId){
        $where[]= ['id','=',$specialId];
        $item = app('model_reward_item')->select('id as item_id','name as item_name','type as item_type')->where($where)->first();
        return $item;
    }

    //type =4 特效
    static function special($specialId){
        $specialRes = app("model_mall_products")->where([
            ["id", '=', $specialId],
            ["category_id", '=', 4],
        ])->select('id as item_id','title as item_name') ->first();
        if (empty($specialRes)) {
            return [] ;
        }
        $specialRes['item_type']=2;
        return $specialRes  ;
    }


    //type=6
    static function gift($giftId)
    {
        $giftRes = app("model_gift")->where([
            ["id", '=', $giftId],
            ["type", '=', 3],
            ["sold", '=', 1]
        ])->select('id as item_id','name as item_name') ->first();
        if (empty($giftRes)) {
            return [] ;
        }
        $giftRes['item_type']=6;
        return $giftRes  ;
    }
    //type=3
    static function horse($horseId)
    {
        $rideRes = app("model_mall_products")->where([
            ["id", '=', $horseId],
            ["category_id", '=', 2],
        ])->select('id as item_id','title as item_name') ->first();
        if (empty($rideRes)) {
            return [] ;
        }
        $rideRes['item_type']=3;
        return $rideRes  ;
    }
    //type=2
    static function headRes($titleId)
    {
        $headRes = app("model_mall_products")->where([
            ["id", '=', $titleId],
            ["category_id", '=', 1],
        ])->select('id as item_id','title as item_name') ->first();
        if (empty($headRes)) {
            return [] ;
        }
        $headRes['item_type']=2;
        return $headRes  ;
    }
}
